<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <!-- <el-form-item label="微信号" prop="wechat">
        <el-input
          v-model="queryParams.wechat"
          placeholder="请输入微信号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="手机号" prop="phone">
        <el-input
          v-model="queryParams.phone"
          placeholder="请输入手机号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="姓名" prop="nickname">
        <el-input
          v-model="queryParams.nickname"
          placeholder="请输入姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="粉丝数" prop="fansNum">
        <el-input
          v-model="queryParams.fansNum"
          placeholder="请输入粉丝数"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="性别" prop="gender">
        <el-input
          v-model="queryParams.gender"
          placeholder="请输入性别"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="城市" prop="city">
        <el-input
          v-model="queryParams.city"
          placeholder="请输入城市"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="是否有联系方式" prop="contactIcon">
        <el-input
          v-model="queryParams.contactIcon"
          placeholder="请输入是否有联系方式"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="近30天视频数量(数量应该多于20)" prop="allVideoNum30d">
        <el-input
          v-model="queryParams.allVideoNum30d"
          placeholder="请输入近30天视频数量(数量应该多于20)"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="近30天直播数量(数量应该多于20)" prop="allLiveNum30d">
        <el-input
          v-model="queryParams.allLiveNum30d"
          placeholder="请输入近30天直播数量(数量应该多于20)"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="千次观看成交量" prop="gpmLow">
        <el-input
          v-model="queryParams.gpmLow"
          placeholder="请输入千次观看成交量"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="观看次数" prop="watchingTimes">
        <el-input
          v-model="queryParams.watchingTimes"
          placeholder="请输入观看次数"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="30天中最高的销售额" prop="saleD30High">
        <el-input
          v-model="queryParams.saleD30High"
          placeholder="请输入30天中最高的销售额"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="销售数据表中的销售前5种类信息 DarenHomeSellDataDto" prop="categoryTopDesc">
        <el-input
          v-model="queryParams.categoryTopDesc"
          placeholder="请输入销售数据表中的销售前5种类信息 DarenHomeSellDataDto"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="销售数据表中的品牌前5信息 DarenHomeSellDataDto" prop="brandTopDecs">
        <el-input
          v-model="queryParams.brandTopDecs"
          placeholder="请输入销售数据表中的品牌前5信息 DarenHomeSellDataDto"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="是否有云雀" prop="showLark">
        <el-input
          v-model="queryParams.showLark"
          placeholder="请输入是否有云雀"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="是否有手机号" prop="showPhone">
        <el-input
          v-model="queryParams.showPhone"
          placeholder="请输入是否有手机号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="是否有微信号" prop="showWechat">
        <el-input
          v-model="queryParams.showWechat"
          placeholder="请输入是否有微信号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="主要带的货品" prop="mainCate">
        <el-input
          v-model="queryParams.mainCate"
          placeholder="请输入主要带的货品"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="归属人" prop="owner">
        <el-input
          v-model="queryParams.owner"
          placeholder="请输入归属人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="归属时间" prop="ownerTime">
        <el-date-picker clearable
          v-model="queryParams.ownerTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择归属时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="添加的微信" prop="addWechat">
        <el-input
          v-model="queryParams.addWechat"
          placeholder="请输入添加的微信"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="添加时的备注" prop="notes">
        <el-input
          v-model="queryParams.notes"
          placeholder="请输入添加时的备注"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="需不需要再看能不能加" prop="canAdd">
        <el-input
          v-model="queryParams.canAdd"
          placeholder="请输入需不需要再看能不能加"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="近30天最低销售额" prop="saleD30Low">
        <el-input
          v-model="queryParams.saleD30Low"
          placeholder="请输入近30天最低销售额"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item> -->
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['dr:base:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['dr:base:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['dr:base:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['dr:base:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="baseList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="抖音号" align="center" prop="awemeId" />
      <!-- <el-table-column label="关联其他表的uid" align="center" prop="unionUid" /> -->
      <el-table-column label="微信号" align="center" prop="wechat" />
      <el-table-column label="手机号" align="center" prop="phone" />
      <el-table-column label="姓名" align="center" prop="nickname" />
      <el-table-column label="粉丝数" align="center" prop="fansNum" />
      <el-table-column label="性别" align="center" prop="gender" />
      <el-table-column label="城市" align="center" prop="city" />
      <!-- <el-table-column label="是否有联系方式" align="center" prop="contactIcon" /> -->
      <el-table-column label="销售类型" align="center" prop="mainSaleType" />
      <el-table-column label="近30天视频数量" align="center" prop="allVideoNum30d" />
      <el-table-column label="近30天直播数量" align="center" prop="allLiveNum30d" />
      <!-- <el-table-column label="千次观看成交量" align="center" prop="gpmLow" /> -->
      <el-table-column label="观看次数" align="center" prop="watchingTimes" />
      <el-table-column label="30天中最高的销售额" align="center" prop="saleD30High" />
      <el-table-column label="销售数据表中的销售前5种类信息 DarenHomeSellDataDto" align="center" prop="categoryTopDesc" />
      <el-table-column label="销售数据表中的品牌前5信息 DarenHomeSellDataDto" align="center" prop="brandTopDecs" />
      <!-- <el-table-column label="是否有云雀" align="center" prop="showLark" />
      <el-table-column label="是否有手机号" align="center" prop="showPhone" />
      <el-table-column label="是否有微信号" align="center" prop="showWechat" /> -->
      <el-table-column label="主要带的货品" align="center" prop="mainCate" />
      <!-- <el-table-column label="归属人" align="center" prop="owner" /> -->
      <el-table-column label="归属时间" align="center" prop="ownerTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.ownerTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <!-- <el-table-column label="添加的微信" align="center" prop="addWechat" />
      <el-table-column label="添加时的备注" align="center" prop="notes" />
      <el-table-column label="需不需要再看能不能加" align="center" prop="canAdd" /> -->
      <el-table-column label="近30天最低销售额" align="center" prop="saleD30Low" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['dr:base:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['dr:base:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改达人列页信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="关联其他表的uid" prop="unionUid">
          <el-input v-model="form.unionUid" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="微信号" prop="wechat">
          <el-input v-model="form.wechat" placeholder="请输入微信号" />
        </el-form-item>
        <el-form-item label="手机号" prop="phone">
          <el-input v-model="form.phone" placeholder="请输入手机号" />
        </el-form-item>
        <el-form-item label="姓名" prop="nickname">
          <el-input v-model="form.nickname" placeholder="请输入姓名" />
        </el-form-item>
        <el-form-item label="粉丝数" prop="fansNum">
          <el-input v-model="form.fansNum" placeholder="请输入粉丝数" />
        </el-form-item>
        <el-form-item label="性别" prop="gender">
          <el-input v-model="form.gender" placeholder="请输入性别" />
        </el-form-item>
        <el-form-item label="城市" prop="city">
          <el-input v-model="form.city" placeholder="请输入城市" />
        </el-form-item>
        <el-form-item label="是否有联系方式" prop="contactIcon">
          <el-input v-model="form.contactIcon" placeholder="请输入是否有联系方式" />
        </el-form-item>
        <el-form-item label="近30天视频数量(数量应该多于20)" prop="allVideoNum30d">
          <el-input v-model="form.allVideoNum30d" placeholder="请输入近30天视频数量(数量应该多于20)" />
        </el-form-item>
        <el-form-item label="近30天直播数量(数量应该多于20)" prop="allLiveNum30d">
          <el-input v-model="form.allLiveNum30d" placeholder="请输入近30天直播数量(数量应该多于20)" />
        </el-form-item>
        <el-form-item label="千次观看成交量" prop="gpmLow">
          <el-input v-model="form.gpmLow" placeholder="请输入千次观看成交量" />
        </el-form-item>
        <el-form-item label="观看次数" prop="watchingTimes">
          <el-input v-model="form.watchingTimes" placeholder="请输入观看次数" />
        </el-form-item>
        <el-form-item label="30天中最高的销售额" prop="saleD30High">
          <el-input v-model="form.saleD30High" placeholder="请输入30天中最高的销售额" />
        </el-form-item>
        <el-form-item label="销售数据表中的销售前5种类信息 DarenHomeSellDataDto" prop="categoryTopDesc">
          <el-input v-model="form.categoryTopDesc" placeholder="请输入销售数据表中的销售前5种类信息 DarenHomeSellDataDto" />
        </el-form-item>
        <el-form-item label="销售数据表中的品牌前5信息 DarenHomeSellDataDto" prop="brandTopDecs">
          <el-input v-model="form.brandTopDecs" placeholder="请输入销售数据表中的品牌前5信息 DarenHomeSellDataDto" />
        </el-form-item>
        <el-form-item label="是否有云雀" prop="showLark">
          <el-input v-model="form.showLark" placeholder="请输入是否有云雀" />
        </el-form-item>
        <el-form-item label="是否有手机号" prop="showPhone">
          <el-input v-model="form.showPhone" placeholder="请输入是否有手机号" />
        </el-form-item>
        <el-form-item label="是否有微信号" prop="showWechat">
          <el-input v-model="form.showWechat" placeholder="请输入是否有微信号" />
        </el-form-item>
        <el-form-item label="主要带的货品" prop="mainCate">
          <el-input v-model="form.mainCate" placeholder="请输入主要带的货品" />
        </el-form-item>
        <el-form-item label="归属人" prop="owner">
          <el-input v-model="form.owner" placeholder="请输入归属人" />
        </el-form-item>
        <el-form-item label="归属时间" prop="ownerTime">
          <el-date-picker clearable
            v-model="form.ownerTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择归属时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="添加的微信" prop="addWechat">
          <el-input v-model="form.addWechat" placeholder="请输入添加的微信" />
        </el-form-item>
        <el-form-item label="添加时的备注" prop="notes">
          <el-input v-model="form.notes" placeholder="请输入添加时的备注" />
        </el-form-item>
        <el-form-item label="需不需要再看能不能加" prop="canAdd">
          <el-input v-model="form.canAdd" placeholder="请输入需不需要再看能不能加" />
        </el-form-item>
        <el-form-item label="近30天最低销售额" prop="saleD30Low">
          <el-input v-model="form.saleD30Low" placeholder="请输入近30天最低销售额" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listBase, getBase, delBase, addBase, updateBase } from "@/api/dr/base"

export default {
  name: "Base",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 达人列页信息表格数据
      baseList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        unionUid: null,
        wechat: null,
        phone: null,
        nickname: null,
        fansNum: null,
        gender: null,
        city: null,
        contactIcon: null,
        mainSaleType: null,
        allVideoNum30d: null,
        allLiveNum30d: null,
        gpmLow: null,
        watchingTimes: null,
        saleD30High: null,
        categoryTopDesc: null,
        brandTopDecs: null,
        showLark: null,
        showPhone: null,
        showWechat: null,
        mainCate: null,
        owner: null,
        ownerTime: null,
        addWechat: null,
        notes: null,
        canAdd: null,
        saleD30Low: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        nickname: [
          { required: true, message: "姓名不能为空", trigger: "blur" }
        ],
      }
    }
  },
  created() {
    this.getList()
  },
  methods: {
    /** 查询达人列页信息列表 */
    getList() {
      this.loading = true
      listBase(this.queryParams).then(response => {
        this.baseList = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    // 取消按钮
    cancel() {
      this.open = false
      this.reset()
    },
    // 表单重置
    reset() {
      this.form = {
        awemeId: null,
        unionUid: null,
        wechat: null,
        phone: null,
        nickname: null,
        fansNum: null,
        gender: null,
        city: null,
        contactIcon: null,
        mainSaleType: null,
        allVideoNum30d: null,
        allLiveNum30d: null,
        gpmLow: null,
        watchingTimes: null,
        saleD30High: null,
        updateTime: null,
        createTime: null,
        categoryTopDesc: null,
        brandTopDecs: null,
        showLark: null,
        showPhone: null,
        showWechat: null,
        mainCate: null,
        owner: null,
        ownerTime: null,
        addWechat: null,
        notes: null,
        canAdd: null,
        saleD30Low: null
      }
      this.resetForm("form")
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm")
      this.handleQuery()
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.awemeId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset()
      this.open = true
      this.title = "添加达人列页信息"
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset()
      const awemeId = row.awemeId || this.ids
      getBase(awemeId).then(response => {
        this.form = response.data
        this.open = true
        this.title = "修改达人列页信息"
      })
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.awemeId != null) {
            updateBase(this.form).then(response => {
              this.$modal.msgSuccess("修改成功")
              this.open = false
              this.getList()
            })
          } else {
            addBase(this.form).then(response => {
              this.$modal.msgSuccess("新增成功")
              this.open = false
              this.getList()
            })
          }
        }
      })
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const awemeIds = row.awemeId || this.ids
      this.$modal.confirm('是否确认删除达人列页信息编号为"' + awemeIds + '"的数据项？').then(function() {
        return delBase(awemeIds)
      }).then(() => {
        this.getList()
        this.$modal.msgSuccess("删除成功")
      }).catch(() => {})
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('dr/base/export', {
        ...this.queryParams
      }, `base_${new Date().getTime()}.xlsx`)
    }
  }
}
</script>
